package com.jida.tijian.service;

import com.jida.tijian.domain.Doctor;
import com.jida.tijian.dto.ResponseObject;
import com.jida.tijian.exception.TijianAPPException;
import com.jida.tijian.exception.TijianAPPExceptionEnum;
import com.jida.tijian.mapper.DoctorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    DoctorMapper doctorMapper;

    @Override
    public ResponseObject doctorLogin(Doctor doctor){
       // int a=10/0;
        Doctor result= doctorMapper.selectByDocCode(doctor);
        ResponseObject responseObject = null;

        if(result == null) {
            //System.out.println("没有找到该名医生");
    //        return new ResponseObject(3001,"您尚未注册");
            throw new TijianAPPException(TijianAPPExceptionEnum.DOCTOR_NOT_REGISTER.getCode(),
                    TijianAPPExceptionEnum.DOCTOR_NOT_REGISTER.getMessage());
        }else if(!result.getPassword().equals(doctor.getPassword())){
            throw new TijianAPPException(TijianAPPExceptionEnum.DOCCODE_OR_PASSWORD_IS_WORRY.getCode(),
                   TijianAPPExceptionEnum.DOCCODE_OR_PASSWORD_IS_WORRY.getMessage());
   //         return new ResponseObject(3002,"密码或账号错误");

        }
        result.setPassword("");
        responseObject = new ResponseObject(ResponseObject.SUCCESS_STATUS,ResponseObject.SUCCESS_DESC,result);
        return responseObject;
    }

}
